package com.tengju.bff.infrastructure.export.repo;

import com.tengju.bff.infrastructure.export.convert.TableVoConvert;
import com.tengju.bff.interfaces.manage.crm.crowd.facade.CrowdAnalysisFacade;
import com.tengju.bff.interfaces.manage.crm.crowd.vo.CrowdListForm;
import com.tengju.bff.interfaces.shared.TableVO;
import com.tengju.bff.interfaces.shared.export.CrowdAnalysisExportQuery;
import com.tengju.export.domain.record.ExportDataSourceRepository;
import com.tengju.export.domain.record.Query;
import com.tengju.export.domain.record.Table;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: 李大仙
 * @date: 2021/8/23 2:39 下午
 */
@Service("crowdAnalysisExportDataSourceRepository")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CrowdAnalysisExportDataSourceRepository implements ExportDataSourceRepository {

    private final CrowdAnalysisFacade crowdAnalysisFacade;

    @Override
    public Table batchFindDataSource(Query query) {
        CrowdAnalysisExportQuery exportQuery = (CrowdAnalysisExportQuery) query;
        CrowdListForm form = new CrowdListForm();
        form.setGenSecIdCodes(exportQuery.getGenSecIdCodes());
        form.setPageIndex(exportQuery.getPageIndex());
        form.setPageSize(exportQuery.getPageSize());
        form.setIdCode(exportQuery.getIdCode());
        form.setBelongGenSecIdCode(exportQuery.getBelongGenSecIdCode());
        form.setBelongEcIdCode(exportQuery.getBelongEcIdCode());
        form.setBelongServiceProviderIdCode(exportQuery.getBelongServiceProviderIdCode());
        form.setDirect(exportQuery.isDirect());
        form.setTagName(exportQuery.getTagName());
        form.setTagValue(exportQuery.getTagValue());
        form.setOrderColumn(exportQuery.getOrderColumn());
        form.setOrderType(exportQuery.getOrderType());
        TableVO tableVO = crowdAnalysisFacade.list(form);
        return TableVoConvert.convert(tableVO);
    }
}
